/**
 * 
 */
package com.hexacta.hrs.services.report.impl;

import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;

import com.hexacta.hrs.report.Report;
import com.hexacta.hrs.services.report.ReportService;

/**
 * @author mfunes
 *
 */
public class ReportServiceImpl implements ReportService {

	private Map<String, String> reportTemplateMap;
	private Map<String, Report> reportMap;
	private Map<String, String> reportsWithFilters;

    public Map<String, String> getReportsWithFilters() {
        return reportsWithFilters;
    }

    public void setReportsWithFilters(Map<String, String> reportsWithFilters) {
        this.reportsWithFilters = reportsWithFilters;
    }

    public Map<String, String> getReportTemplateMap() {
		return reportTemplateMap;
	}

	public void setReportTemplateMap(Map<String, String> reportTemplateMap) {
		this.reportTemplateMap = reportTemplateMap;
	}

	public Map<String, Report> getReportMap() {
		return reportMap;
	}

	public void setReportMap(Map<String, Report> reportMap) {
		this.reportMap = reportMap;
	}

	/** {@link InheritedDoc}. */
	public ByteArrayOutputStream createPDFReport(String reportName) {
		return this.createPDFReport(reportName, null, null);
	}

	/** {@link InheritedDoc}. */
	public ByteArrayOutputStream createXLSReport(String reportName) {
		return this.createXLSReport(reportName, null, null);
	}

	/** {@link InheritedDoc}. */
	public ByteArrayOutputStream createPDFReport(String reportName,	Map<String, Object> filters, Map<String, Object> parameters) {
		Report report = reportMap.get(reportName);
		if(report==null){
			 throw new RuntimeException("Report Manager for "+reportName+" Not Found");
		}
		String reportTemplateLocation = reportTemplateMap.get(reportName);
		if (reportName.equalsIgnoreCase("Active Employee Carreer Report")) {
		filters = new HashMap<String, Object>();
		}
		return report.createPDFReport(reportName, reportTemplateLocation, filters, parameters);	
	}

	/** {@link InheritedDoc}. */
	public ByteArrayOutputStream createXLSReport(String reportName,	Map<String, Object> filters, Map<String, Object> parameters) {
		Report report = reportMap.get(reportName);
		if(report==null){
			throw new RuntimeException("Report Manager for "+reportName+" Not Found");
		}
		String reportTemplateLocation = reportTemplateMap.get(reportName);
		if (reportName.equalsIgnoreCase("Active Employee Carreer Report")) {
			filters = new HashMap<String, Object>();
		}
		return report.createXLSReport(reportName, reportTemplateLocation, filters, parameters);
	}

    @Override
    public String reportAcceptFilters(String reportName) {
        if(reportsWithFilters.containsKey(reportName)){
            return reportsWithFilters.get(reportName);
        }
        return "";
    }

}
